#!/bin/bash

echo "Starting full sync from source to target..."

# 等待数据库服务启动
echo "Waiting for databases to be ready..."
sleep 10

# 检查源数据库连接
echo "Checking source database connection..."
mongosh --host 192.168.3.3:27027 --username admin --password passwordA --authenticationDatabase admin --eval "db.runCommand('ping')"

if [ $? -ne 0 ]; then
    echo "Error: Cannot connect to source database"
    exit 1
fi

# 检查目标数据库连接
echo "Checking target database connection..."
mongosh --host 192.168.3.3:27020 --username admin --password passwordB --authenticationDatabase admin --eval "db.runCommand('ping')"

if [ $? -ne 0 ]; then
    echo "Error: Cannot connect to target database"
    exit 1
fi

# 执行全量同步
echo "Starting mongosync full sync..."
mongosync \
    --acceptDisclaimer \
    --cluster0 "mongodb://admin:passwordA@192.168.3.3:27027" \
    --cluster1 "mongodb://admin:passwordB@192.168.3.3:27020" \
    --verbosity INFO \
    --disableTelemetry \

mongosync \
    --cluster0 "mongodb://admin:passwordA@192.168.3.3:27027" \
    --cluster1 "mongodb://admin:passwordB@192.168.3.3:27020" \
    --verbosity DEBUG \
    --disableTelemetry \



echo "Full sync completed!" 